<html>
<head><meta charset="utf-8"><title>Deref patterns · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html">Deref patterns</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222466751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222466751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222466751">(Jan 12 2021 at 17:34)</a>:</h4>
<p>I think this thread on internals is worth looking at: <a href="https://internals.rust-lang.org/t/somewhat-random-idea-deref-patterns/13813">https://internals.rust-lang.org/t/somewhat-random-idea-deref-patterns/13813</a></p>



<a name="222466786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222466786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222466786">(Jan 12 2021 at 17:34)</a>:</h4>
<p>Seems like a substantial ergonomic improvement.</p>



<a name="222470460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222470460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222470460">(Jan 12 2021 at 18:00)</a>:</h4>
<p>There's a syntax question that needs resolving.</p>



<a name="222470491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222470491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222470491">(Jan 12 2021 at 18:00)</a>:</h4>
<p>I think it'd be very nice to be able to match <code>Option&lt;String&gt;</code> with <code>Some("hello")</code>.</p>



<a name="222470844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222470844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222470844">(Jan 12 2021 at 18:03)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="119031">@Esteban Küber</span>, who was talking to me about this recently</p>



<a name="222470854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222470854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222470854">(Jan 12 2021 at 18:03)</a>:</h4>
<p>I'm in favor of some kind of deref pattern</p>



<a name="222470878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222470878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222470878">(Jan 12 2021 at 18:03)</a>:</h4>
<p>I'd prefer not to have syntax</p>



<a name="222471136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222471136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222471136">(Jan 12 2021 at 18:05)</a>:</h4>
<p>Previous internal thread on the same subject (by me) <a href="https://internals.rust-lang.org/t/pre-pre-rfc-match-ergonomics-for-container-types-restricted-method-calls-in-patterns/13371">https://internals.rust-lang.org/t/pre-pre-rfc-match-ergonomics-for-container-types-restricted-method-calls-in-patterns/13371</a></p>



<a name="222471301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222471301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222471301">(Jan 12 2021 at 18:06)</a>:</h4>
<p>I'm getting back to writing a proper RFC for this between this week and the next</p>



<a name="222471468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222471468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222471468">(Jan 12 2021 at 18:08)</a>:</h4>
<p>After that thread I am of the mind that _not_ having any syntax _can_ be reasonable because <code>Deref</code> is already hidden through coercions in enough places that there's _an expectation_ that <code>Deref</code> is "cheap" (despite there being no "language level" assurances of it)</p>



<a name="222471624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222471624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222471624">(Jan 12 2021 at 18:09)</a>:</h4>
<p>An alternative approach would be to have some way of letting users have (de)structuring with logic, but we already have <code>Deref</code> that we can use for this</p>



<a name="222471642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222471642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222471642">(Jan 12 2021 at 18:09)</a>:</h4>
<p>it seems like a pretty big step to depart from patterns being fully structural, without user code</p>



<a name="222472106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222472106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222472106">(Jan 12 2021 at 18:13)</a>:</h4>
<p>We already have <code>box</code> in nightly, and I think that _that_ is the wrong solution, we need something that end users can implement for their own types. If we have to add a keyword/sigil, so be it, but I am convinced we need the _feature_ in some form.</p>



<a name="222473220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222473220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222473220">(Jan 12 2021 at 18:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119031">Esteban Küber</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222471468">said</a>:</p>
<blockquote>
<p>After that thread I am of the mind that _not_ having any syntax _can_ be reasonable because <code>Deref</code> is already hidden through coercions in enough places that there's _an expectation_ that <code>Deref</code> is "cheap" (despite there being no "language level" assurances of it)</p>
</blockquote>
<p>"cheap" isn't my concern. The compiler allowing broader type inference is my concern.</p>



<a name="222473301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222473301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222473301">(Jan 12 2021 at 18:22)</a>:</h4>
<p>Matching <code>Option&lt;String&gt;</code> against <code>Some("hello")</code> seems reasonable, and shouldn't have any broader type inference concerns.</p>



<a name="222473355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222473355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222473355">(Jan 12 2021 at 18:22)</a>:</h4>
<p>Matching <code>Option&lt;String&gt;</code> against <code>Some(x)</code> and allowing type inference to consider the possibility that <code>x</code> isn't <code>String</code> concerns me.</p>



<a name="222474005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222474005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222474005">(Jan 12 2021 at 18:27)</a>:</h4>
<p>patterns would still have to be constant, no? so <code>Some(x)</code> wouldn't need inference if that's a <code>const x</code></p>



<a name="222474248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222474248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222474248">(Jan 12 2021 at 18:29)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> <code>box</code> patterns also raise the question of a <code>DerefMove</code>, if you want this for user types</p>



<a name="222474526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222474526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222474526">(Jan 12 2021 at 18:31)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> Not sure what you mean by that?</p>



<a name="222474556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222474556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222474556">(Jan 12 2021 at 18:31)</a>:</h4>
<p><code>x</code> is conventionally a variable, not a constant (a constant would be in uppercase).</p>



<a name="222474651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222474651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222474651">(Jan 12 2021 at 18:32)</a>:</h4>
<p>oh, you mean <code>x</code> as a new binding, not a value to be matched</p>



<a name="222474698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222474698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222474698">(Jan 12 2021 at 18:33)</a>:</h4>
<p>I don't see why that would ever deref though</p>



<a name="222477389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222477389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222477389">(Jan 12 2021 at 18:53)</a>:</h4>
<p>I can imagine people wanting that.</p>



<a name="222477534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222477534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222477534">(Jan 12 2021 at 18:54)</a>:</h4>
<p>If that's not part of the proposal on the table, that's great.</p>



<a name="222477603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222477603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222477603">(Jan 12 2021 at 18:54)</a>:</h4>
<p>If we're only talking about literals, I have no objections to <code>Deref</code> without any explicit sigil or other marker.</p>



<a name="222477663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222477663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222477663">(Jan 12 2021 at 18:55)</a>:</h4>
<p>It's only where it affects type inference that I feel a sigil should be required.</p>



<a name="222477721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222477721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222477721">(Jan 12 2021 at 18:55)</a>:</h4>
<p>my intuition would be that binding <code>x</code> would take the type as-is, and you can always deref where it's used</p>



<a name="222477833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222477833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222477833">(Jan 12 2021 at 18:56)</a>:</h4>
<p>Aside from the syntax question, there is also a question on whether or not to enforce purity of the deref in some way, if for nothing else, then to allow exhaustive matches across a deref.</p>



<a name="222480500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222480500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222480500">(Jan 12 2021 at 19:15)</a>:</h4>
<p>I get the general impression that people already tend to assume Deref is pure-ish.</p>



<a name="222480642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222480642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222480642">(Jan 12 2021 at 19:16)</a>:</h4>
<p>I'm <em>less</em> concerned about the number of calls to <code>deref</code>, since I suspect in practice many match statements will be able to make one call for most or all of the branches.</p>



<a name="222480703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222480703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222480703">(Jan 12 2021 at 19:17)</a>:</h4>
<p>On exhaustiveness, how bad would it be if we just did exhaustiveness checking <em>assuming</em> that deref didn't return inconsistent results?</p>



<a name="222480758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222480758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222480758">(Jan 12 2021 at 19:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222477721">said</a>:</p>
<blockquote>
<p>my intuition would be that binding <code>x</code> would take the type as-is, and you can always deref where it's used</p>
</blockquote>
<p>One issue with this was raised on the thread, that it would make the types of <code>x</code> and <code>x @ Some(y)</code> different, when matching, say, <code>Box&lt;Option&lt;i32&gt;</code>. One possibility is that binding a pattern that has an implicit dereference would be ill-formed.</p>



<a name="222480871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222480871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222480871">(Jan 12 2021 at 19:18)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> <code>x</code> and <code>x @ Some(y)</code> would both still be identically typed. But it'd make <code>x</code> and <code>x @ Some("hello")</code> different, for instance.</p>



<a name="222480948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222480948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222480948">(Jan 12 2021 at 19:19)</a>:</h4>
<p>I don't think I'd object to <code>x @ Some("hello")</code> working, either.</p>



<a name="222481025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222481025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222481025">(Jan 12 2021 at 19:20)</a>:</h4>
<p>forcing <code>x</code> to be deref'ed? or leaving it <code>Option&lt;String&gt;</code> and deref'ed only for the <code>@...</code> matching?</p>



<a name="222481090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222481090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222481090">(Jan 12 2021 at 19:20)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222480703">said</a>:</p>
<blockquote>
<p>On exhaustiveness, how bad would it be if we just did exhaustiveness checking <em>assuming</em> that deref didn't return inconsistent results?</p>
</blockquote>
<p>Without necessarily considering an implementation, at worst, it could be unsound if the <code>deref</code> is structurally unstable.</p>
<p>As for the assumption <code>deref</code> is already pure, there are a few counterexamples that I listed in the standard library on the thread, notably <code>std::lazy::Lazy</code> and <code>std::lazy::SyncLazy</code>. The guard type for a <code>lazy_static!</code> would also not be a candidate for <code>DerefPure</code>.</p>



<a name="222481466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222481466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222481466">(Jan 12 2021 at 19:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222480871">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <code>x</code> and <code>x @ Some(y)</code> would both still be identically typed. But it'd make <code>x</code> and <code>x @ Some("hello")</code> different, for instance.</p>
</blockquote>
<p>Would it? In the example I gave, the former would include an implicit deref, as <code>Box&lt;Option&lt;i32&gt;&gt;</code> needs to be dereferenced to get match against the <code>Some(y)</code> pattern. At least to me, the type of <code>x</code> intuitively should match the pattern.</p>



<a name="222484516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222484516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222484516">(Jan 12 2021 at 19:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222474248">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="119031">Esteban Küber</span> <code>box</code> patterns also raise the question of a <code>DerefMove</code>, if you want this for user types</p>
</blockquote>
<p>Personally I would like to see the most "permissive" implementation considered but only the most "restrictive" stabilized (at first). Making it possible to get from <code>Box&lt;T&gt;</code> or <code>Arc&lt;T&gt;</code> to <code>&amp;T</code> in a pattern would make a bunch of code much nicer to write. Allowing <code>Cell&lt;T&gt;</code> to <code>&amp;mut T</code> is useful, but a smaller set of use cases which we can potentially consider independently. Allowing <code>Box&lt;T&gt;</code> to <code>T</code> (<code>DerefMove</code>) I would also <em>consider</em> but not <em>address</em> (at least at first, if ever).</p>



<a name="222485880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222485880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222485880">(Jan 12 2021 at 19:57)</a>:</h4>
<blockquote>
<p>Allowing <code>Cell&lt;T&gt;</code> to <code>&amp;mut T</code> is useful</p>
</blockquote>
<p>in theory it could implement <code>DerefMut</code>, but it can't implement <code>Deref</code></p>



<a name="222485911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222485911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222485911">(Jan 12 2021 at 19:57)</a>:</h4>
<p>but I take the rest of your point</p>



<a name="222486689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222486689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222486689">(Jan 12 2021 at 20:03)</a>:</h4>
<p>Regarding <code>DerefPure</code>, I don't see any need for it. If it is desugared to multiple calls, then after inlining the compiler may be able to eliminate the calls; if not, maybe use another syntax</p>



<a name="222486762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222486762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222486762">(Jan 12 2021 at 20:04)</a>:</h4>
<p>Perhaps there is use for a purity annotation that lets the compiler coalesce multiple calls but that's orthogonal to deref patterns</p>



<a name="222487115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222487115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222487115">(Jan 12 2021 at 20:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222486689">said</a>:</p>
<blockquote>
<p>Regarding <code>DerefPure</code>, I don't see any need for it. If it is desugared to multiple calls, then after inlining the compiler may be able to eliminate the calls; if not, maybe use another syntax</p>
</blockquote>
<p>The only thing is that, without <code>DerefPure</code>, it would be impossible to exhaustively match across a <code>Deref</code> pattern</p>



<a name="222487486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222487486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222487486">(Jan 12 2021 at 20:09)</a>:</h4>
<p>Yet another alternative would be to have <em>another</em> trait <code>DerefPattern</code> to give API devs more granular control, but I don't know how I feel about that...</p>



<a name="222487600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222487600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222487600">(Jan 12 2021 at 20:10)</a>:</h4>
<p>What does this trait do? Is it like view patterns in haskell/scala?</p>



<a name="222487639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222487639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222487639">(Jan 12 2021 at 20:10)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119031">Esteban Küber</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222487486">said</a>:</p>
<blockquote>
<p>Yet another alternative would be to have <em>another</em> trait <code>DerefPattern</code> to give API devs more granular control, but I don't know how I feel about that...</p>
</blockquote>
<p>This one seems like a can of worms that I'd personally rather keep shut.</p>



<a name="222488306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222488306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222488306">(Jan 12 2021 at 20:16)</a>:</h4>
<p>Mario, yes</p>



<a name="222488352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222488352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222488352">(Jan 12 2021 at 20:17)</a>:</h4>
<p>Or rather a way to have the same functionality through different means</p>



<a name="222493372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222493372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222493372">(Jan 12 2021 at 20:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222480703">said</a>:</p>
<blockquote>
<p>On exhaustiveness, how bad would it be if we just did exhaustiveness checking <em>assuming</em> that deref didn't return inconsistent results?</p>
</blockquote>
<p>Could be pretty bad. Imagine</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">x</span>: <span class="nc">MyBool</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">bool</span> <span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">match</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kc">true</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="kc">false</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="kc">false</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Assume <code>MyBool</code> derefs to <code>bool</code>, but picks one at random at each call or something. Then there's a good change none of the match arms match, so we get something very undefined. Pretty sure we can't rely on the compiler only derefing once either, a more complex example could work around that.</p>



<a name="222493791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222493791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222493791">(Jan 12 2021 at 21:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222481025">said</a>:</p>
<blockquote>
<p>forcing <code>x</code> to be deref'ed? or leaving it <code>Option&lt;String&gt;</code> and deref'ed only for the <code>@...</code> matching?</p>
</blockquote>
<p>Making <code>x</code> an <code>Option&lt;&amp;str&gt;</code> to match the pattern.</p>



<a name="222494068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222494068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222494068">(Jan 12 2021 at 21:03)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> <span class="user-mention" data-user-id="245339">@Nadrieril</span> To clarify, I wasn't imagining that we would just proceed and allow unsoundness. We'd still need to verify what we ended up with. I was more asking "in practice, are Deref implementations sufficiently consistent that this would work".</p>



<a name="222497103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222497103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222497103">(Jan 12 2021 at 21:29)</a>:</h4>
<p>Ok. Btw, knowing the exhaustiveness code, it would be super easy to require an extra <code>_</code> pattern for deref patterns. So we could stabilise deref patterns with the current <code>Deref</code> trait and maybe add <code>DerefPure</code> later backwards-compatibly</p>



<a name="222499468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222499468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222499468">(Jan 12 2021 at 21:49)</a>:</h4>
<p>That honestly seems reasonable. </p>
<p>One question, though. Would it be valid to declare that, even without <code>DerefPure</code>, the number of times each of <code>deref</code> and <code>deref_mut</code> are called when matching deref patterns (and whether or not a particular pattern uses <code>deref</code> and <code>deref_mut</code>, where both are valid) is unspecified?  This could allow implementations to theoretically implement the entire stream of deref patterns as a single call to either <code>deref</code> or <code>deref_mut</code>.</p>



<a name="222511540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222511540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222511540">(Jan 12 2021 at 23:35)</a>:</h4>
<p>The number (and timing) of derefs is dangerously close to "observable means stable"</p>



<a name="222511582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222511582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222511582">(Jan 12 2021 at 23:35)</a>:</h4>
<p>If people have interior mutability in their <code>Deref</code> impl they'll (accidentally or deliberately) rely on the number/order of derefs</p>



<a name="222511655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222511655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222511655">(Jan 12 2021 at 23:36)</a>:</h4>
<p>Drop order was stabilized as-is because changing it would be too breaking, I have a fear that auto(de)ref in patterns would go the same way</p>



<a name="222519460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222519460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222519460">(Jan 13 2021 at 01:16)</a>:</h4>
<p>Would it be difficult to commit to only derefing each thing once? I can't tell if there are patterns that would make this tricky; seems doable as far as I can see</p>



<a name="222520958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222520958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222520958">(Jan 13 2021 at 01:35)</a>:</h4>
<p><span class="user-mention silent" data-user-id="245339">Nadrieril</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222519460">said</a>:</p>
<blockquote>
<p>Would it be difficult to commit to only derefing each thing once? I can't tell if there are patterns that would make this tricky; seems doable as far as I can see</p>
</blockquote>
<p>It's possible, if all derefs are immutable and there are no intervening mutable borrow of the original place in a pattern, or there are no borrow at all of the derefed value in a pattern.</p>



<a name="222559611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222559611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222559611">(Jan 13 2021 at 10:19)</a>:</h4>
<p>Oh I see, mixing mutable and immutable borrows makes this impossible. That makes trying to specify precisely the number of derefs for a given match painful too &gt;&lt;. I think I want DerefPure too now</p>



<a name="222570073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222570073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222570073">(Jan 13 2021 at 12:06)</a>:</h4>
<p>What if we define some restrictive circumstance in which multiple similar looking patterns in a row count as one deref? If you do any of the funny business that Connor mentions then the condition does not apply and you get multiple derefs</p>



<a name="222570784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222570784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222570784">(Jan 13 2021 at 12:15)</a>:</h4>
<p>I'm not entirely sure about the scope of the counterexamples, but I'm thinking something along the lines of: if a contiguous sequence of patterns all contain the same "prefix" of pattern matches, then they will all be grouped into a branch of the case tree, even if that includes a deref pattern match. That way you can still do exhaustive pattern matches as long as you write the matches in the right order. I think it will still work in the presence of pattern guards, because it amounts to a syntactic transformation and so is not constrained by the borrow checker rules (this happens in the desugaring pass before getting to MIR).</p>



<a name="222572323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222572323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222572323">(Jan 13 2021 at 12:31)</a>:</h4>
<p>For example:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">match</span><span class="w"> </span><span class="o">&amp;</span><span class="n">MyBool</span><span class="p">(</span><span class="kc">false</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="o">&amp;*</span><span class="kc">true</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"true"</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="o">&amp;*</span><span class="kc">false</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"false"</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="c1">// exhaustive!</span>
<span class="p">}</span><span class="w"></span>

<span class="c1">// desugars to:</span>
<span class="k">match</span><span class="w"> </span><span class="o">&amp;</span><span class="n">MyBool</span><span class="p">(</span><span class="kc">false</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="o">&amp;**</span><span class="n">x</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="o">&amp;</span><span class="kc">true</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"true"</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="o">&amp;</span><span class="kc">false</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"false"</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">match</span><span class="w"> </span><span class="p">(</span><span class="n">MyBool</span><span class="p">(</span><span class="kc">false</span><span class="p">),</span><span class="w"> </span><span class="n">MyBool</span><span class="p">(</span><span class="kc">true</span><span class="p">))</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">(</span><span class="o">*</span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="o">*</span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"true, {}"</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="p">(</span><span class="o">*</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="o">*</span><span class="kc">true</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"{}, true"</span><span class="p">,</span><span class="w"> </span><span class="n">x</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"other"</span><span class="p">),</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="c1">// desugars to:</span>
<span class="k">match</span><span class="w"> </span><span class="p">(</span><span class="n">MyBool</span><span class="p">(</span><span class="kc">false</span><span class="p">),</span><span class="w"> </span><span class="n">MyBool</span><span class="p">(</span><span class="kc">true</span><span class="p">))</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">(</span><span class="k">ref</span><span class="w"> </span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="k">ref</span><span class="w"> </span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="p">(</span><span class="o">&amp;**</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;**</span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="p">(</span><span class="o">&amp;</span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"true, {}"</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="p">(</span><span class="o">&amp;</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="kc">true</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"{}, true"</span><span class="p">,</span><span class="w"> </span><span class="n">x</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"other"</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">match</span><span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">MyBool</span><span class="p">(</span><span class="kc">false</span><span class="p">))</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">Ok</span><span class="p">(</span><span class="o">*</span><span class="kc">true</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"ok true"</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="nb">Err</span><span class="p">(</span><span class="n">_</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"err"</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="nb">Ok</span><span class="p">(</span><span class="o">*</span><span class="kc">false</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"ok false"</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="c1">// exhaustiveness error, unless you add</span>
<span class="w">    </span><span class="nb">Ok</span><span class="p">(</span><span class="n">_</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"ok"</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="c1">// desugars to:</span>
<span class="k">match</span><span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">MyBool</span><span class="p">(</span><span class="kc">false</span><span class="p">))</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">Ok</span><span class="p">(</span><span class="k">ref</span><span class="w"> </span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="o">&amp;**</span><span class="n">x</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="o">&amp;</span><span class="kc">true</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"ok true"</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="o">&amp;**</span><span class="n">x</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="o">&amp;</span><span class="kc">false</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"ok false"</span><span class="p">),</span><span class="w"></span>
<span class="w">            </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"ok"</span><span class="p">)</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="nb">Err</span><span class="p">(</span><span class="n">_</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"err"</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="222572905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222572905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222572905">(Jan 13 2021 at 12:37)</a>:</h4>
<p>It would also be possible to add rules to enable coalescing even in the last case, for example if you say that the <code>Err(_)</code> cases are removed from the list of matches when determining if the derefs under <code>Ok</code> are contiguous, but that seems like it would be harder for programmers to reason about even though it allows more free rearrangement of patterns. The idea here is that the coalescing rule is simple enough that people can predictably trigger it so that exhausiveness errors are easily addressed while still letting people write big matches</p>



<a name="222577391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222577391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222577391">(Jan 13 2021 at 13:20)</a>:</h4>
<p>I would prefer not to have to guess whether my code will compile or not :/ autoderef already causes a lot of confusion there, if you look in #beginners on discord there are an awful lot of links to <a href="https://img.ifunny.co/images/7ab362ba5b3a1152f8d0c1b029e94d880d0cd4913a5642cbc79320e212676234_1.jpg">https://img.ifunny.co/images/7ab362ba5b3a1152f8d0c1b029e94d880d0cd4913a5642cbc79320e212676234_1.jpg</a> floating around</p>
<div class="message_inline_image"><a href="https://img.ifunny.co/images/7ab362ba5b3a1152f8d0c1b029e94d880d0cd4913a5642cbc79320e212676234_1.jpg"><img src="https://img.ifunny.co/images/7ab362ba5b3a1152f8d0c1b029e94d880d0cd4913a5642cbc79320e212676234_1.jpg"></a></div>



<a name="222577457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222577457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222577457">(Jan 13 2021 at 13:21)</a>:</h4>
<p>I would much rather have DerefPure</p>



<a name="222577830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222577830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222577830">(Jan 13 2021 at 13:24)</a>:</h4>
<p>What I don't like about DerefPure is that it makes an assertion about purity that I as code author may not want</p>



<a name="222577973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222577973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222577973">(Jan 13 2021 at 13:25)</a>:</h4>
<p>I think it's much more likely that when writing a big nested pattern match you want as few deref calls as required</p>



<a name="222577994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222577994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222577994">(Jan 13 2021 at 13:25)</a>:</h4>
<p>whether or not those calls are pure</p>



<a name="222578116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222578116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222578116">(Jan 13 2021 at 13:26)</a>:</h4>
<p>but the general syntax of pattern matching requires writing the same deref over and over again even though that's not the intent</p>



<a name="222579542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222579542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222579542">(Jan 13 2021 at 13:37)</a>:</h4>
<p>Right, but at least it's consistent. I agree it's a common problem, I'm just not sure compiler magic for the common cases is the right solution.</p>



<a name="222579664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222579664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222579664">(Jan 13 2021 at 13:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222577391">said</a>:</p>
<blockquote>
<p>I would prefer not to have to guess whether my code will compile or not :/ autoderef already causes a lot of confusion there, if you look in #beginners on discord there are an awful lot of links to <a href="https://img.ifunny.co/images/7ab362ba5b3a1152f8d0c1b029e94d880d0cd4913a5642cbc79320e212676234_1.jpg">https://img.ifunny.co/images/7ab362ba5b3a1152f8d0c1b029e94d880d0cd4913a5642cbc79320e212676234_1.jpg</a> floating around</p>
</blockquote>
<p>this is something I would personally like to see more information on - I don't think I experience it when writing code, but maybe there's some pattern I just have trained myself to not write. It would be good for this sort of case to try to categorize and document the problem (perhaps as a design note) so that it can be considered more effectlively.</p>



<a name="222579883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222579883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222579883">(Jan 13 2021 at 13:40)</a>:</h4>
<p>I don't think the description I gave is inconsistent? The basic idea is that the "syntax" for building a subtree of the underlying case tree is to write several patterns in a row with the same destructuring pattern. I don't see how else to express something like that without actually writing nested <code>match</code>, which is what we're trying to avoid in the first place</p>



<a name="222579949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222579949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222579949">(Jan 13 2021 at 13:40)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> it normally comes up in the presence of smart pointers, people get confused when they have to do <code>&amp;*string</code> or whatever. With boxes it's even worse because sometimes you have <code>&amp;**</code>.</p>
<p>I think RA's type hints help with this to some extent, but autoderef works just enough of the time that it's confusing when it doesn't.</p>



<a name="222580027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222580027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222580027">(Jan 13 2021 at 13:41)</a>:</h4>
<p>hm, it feels like that's rather an argument for this feature? but again, without more detail hard to say</p>



<a name="222580069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222580069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222580069">(Jan 13 2021 at 13:41)</a>:</h4>
<p>I'll try to come up with an example this afternoon</p>



<a name="222580186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222580186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222580186">(Jan 13 2021 at 13:42)</a>:</h4>
<p>most of the time when I end up writing &amp;* or so, it's because I'm e.g. matching and the match needs &amp;str</p>



<a name="222580312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222580312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222580312">(Jan 13 2021 at 13:43)</a>:</h4>
<p><span class="user-mention" data-user-id="271719">@Mario Carneiro</span> sorry, consistent was the wrong word. Your idea seems specified pretty well, I just feel like I'd have trouble telling the rules by looking at code. Sort of like how I'm never sure which function override applies in C++.</p>



<a name="222581144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222581144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222581144">(Jan 13 2021 at 13:49)</a>:</h4>
<p>Like I said, I can imagine ways to make it easier to use / succeed in more cases, but not without making it even worse on that axis. It's probably better if you aren't sure of the rules to think about it the way Connor mentioned earlier: the number of derefs is unspecified (or rather, the specification is more complicated than you would like to think about), so don't rely on it, keep your derefs pure or write nested matches if you need to be precise about it</p>



<a name="222606694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222606694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222606694">(Jan 13 2021 at 16:26)</a>:</h4>
<p>Here's another idea: rustc randomizes whether to group similar derefs on purpose, to prevent people from relying on it x)</p>



<a name="222609933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222609933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222609933">(Jan 13 2021 at 16:48)</a>:</h4>
<p>Well that's why I'd say that the number, timings, and kinds of <code>deref</code> calls be unspecified.</p>



<a name="222614099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222614099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222614099">(Jan 13 2021 at 17:15)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> Why &amp;* in that case, rather than .as_str() ?</p>



<a name="222615704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222615704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222615704">(Jan 13 2021 at 17:25)</a>:</h4>
<p>Well, I prefer as_str, but it's not always possible on non-String types, e.g. with Arc I think.</p>



<a name="222619722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222619722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222619722">(Jan 13 2021 at 17:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222577457">said</a>:</p>
<blockquote>
<p>I would much rather have DerefPure</p>
</blockquote>
<p>At this point, I'm wondering if, instead of having a <code>DerefPure</code> trait that can be freely implemented, in the first version of this, it's limited to standard library types that are already defined as being candidates for <code>DerefPure</code>.</p>



<a name="222621092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222621092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222621092">(Jan 13 2021 at 18:03)</a>:</h4>
<p>Someone on irlo suggested it could be limited to const Deref impls.</p>



<a name="222621481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222621481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222621481">(Jan 13 2021 at 18:05)</a>:</h4>
<p>Yeah, that may work as well. The only thing would be if that would be more restrictive then necessary (it also would block it on const trait impls).</p>



<a name="222621583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222621583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222621583">(Jan 13 2021 at 18:06)</a>:</h4>
<p>This would require an MCP, right?</p>



<a name="222623601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222623601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222623601">(Jan 13 2021 at 18:21)</a>:</h4>
<p>can const-eval handle the types we care about here?</p>



<a name="222623709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222623709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222623709">(Jan 13 2021 at 18:22)</a>:</h4>
<p>in particular, AFAIK dereferencing raw pointers isn't supported</p>



<a name="222624400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222624400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222624400">(Jan 13 2021 at 18:27)</a>:</h4>
<p>I guess that's <a href="https://github.com/rust-lang/rust/issues/51911">#51911</a></p>



<a name="222625300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222625300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222625300">(Jan 13 2021 at 18:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222609933">said</a>:</p>
<blockquote>
<p>Well that's why I'd say that the number, timings, and kinds of <code>deref</code> calls be unspecified.</p>
</blockquote>
<p>Yeah, the problem with this was that even if unspecified, people could start relying on it like they did with drop order.</p>



<a name="222625603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222625603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222625603">(Jan 13 2021 at 18:36)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222619722">said</a>:</p>
<blockquote>
<p>At this point, I'm wondering if, instead of having a <code>DerefPure</code> trait that can be freely implemented, in the first version of this, it's limited to standard library types that are already defined as being candidates for <code>DerefPure</code>.</p>
</blockquote>
<p>I like this! This would be like making DerefPure perma-unstable. This would allow us to test the feature at a real scale without comitting on much</p>



<a name="222625835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222625835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222625835">(Jan 13 2021 at 18:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="245339">Nadrieril</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222625300">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222609933">said</a>:</p>
<blockquote>
<p>Well that's why I'd say that the number, timings, and kinds of <code>deref</code> calls be unspecified.</p>
</blockquote>
<p>Yeah, the problem with this was that even if unspecified, people could start relying on it like they did with drop order.</p>
</blockquote>
<p>Well, of course, if it's unspecified, then the compiler could add an option to randomize it and break any code relying on it.  People can already rely on unspecified things, like the layout of a repr(Rust). However, the fact it's unspecified means that implementors don't really have to care about people relying on it and can break it at any time they choose.</p>



<a name="222626135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222626135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222626135">(Jan 13 2021 at 18:41)</a>:</h4>
<p>In principle yes, but apparently in practice we decided we couldn't change drop order because it would break too much code. Anyway, my point about randomizing was made in jest dw</p>



<a name="222626167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222626167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222626167">(Jan 13 2021 at 18:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="245339">Nadrieril</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222625603">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222619722">said</a>:</p>
<blockquote>
<p>At this point, I'm wondering if, instead of having a <code>DerefPure</code> trait that can be freely implemented, in the first version of this, it's limited to standard library types that are already defined as being candidates for <code>DerefPure</code>.</p>
</blockquote>
<p>I like this! This would be like making DerefPure perma-unstable. This would allow us to test the feature at a real scale without comitting on much</p>
</blockquote>
<p>Well, hopefully not <em>perma</em>-unstable. At some point it would be a good idea to look into extending the feature to user-provided types. But this starting point would probably be reasonable enough. </p>
<p>I have a list of types that would be candidates for this immediately on the IRLO thread (hopefully I didn't miss any types).</p>



<a name="222642731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222642731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222642731">(Jan 13 2021 at 20:43)</a>:</h4>
<p>I would like to bring this idea forward. I assume the next step would be to file a major change proposal. If someone could inform me of the necessary steps for that, that would be helpful.</p>



<a name="222643783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222643783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222643783">(Jan 13 2021 at 20:52)</a>:</h4>
<p>This is a bit tangential, but it'd be cool if the optimizer could take advantage of the purity of the deref as well.  I've seen cases where <code>&amp;mut Vec&lt;T&gt;</code> is noticeably slower than <code>&amp;mut [T]</code> (such as <a href="https://users.rust-lang.org/t/we-all-know-iter-is-faster-than-loop-but-why/51486/3?u=scottmcm">https://users.rust-lang.org/t/we-all-know-iter-is-faster-than-loop-but-why/51486/3?u=scottmcm</a> ), so it might help if the optimizer could tell that the deref is always doing the same thing.</p>



<a name="222717981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222717981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> atagunov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222717981">(Jan 14 2021 at 13:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222623601">said</a>:</p>
<blockquote>
<p>can const-eval handle the types we care about here?<br>
in particular, AFAIK dereferencing raw pointers isn't supported</p>
</blockquote>
<p>There could be another variety of const-eval more tailored to run-time execution.<br>
I have tentatively suggested to name it <a href="https://internals.rust-lang.org/t/const-pure/13824">const(pure)</a></p>



<a name="222722723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222722723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222722723">(Jan 14 2021 at 14:21)</a>:</h4>
<p>I think we'll soon be able to support all kinds of pointer shenanigans. Imo there shouldn't be any <code>Deref</code> impls that aren't <code>const</code>, unless you are explicitly trying to do something nasty</p>



<a name="222728116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728116">(Jan 14 2021 at 15:00)</a>:</h4>
<p><code>Lazy</code> can't have a const deref though, right?</p>



<a name="222728211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728211">(Jan 14 2021 at 15:01)</a>:</h4>
<p>probably not, definitely not yet</p>



<a name="222728218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728218">(Jan 14 2021 at 15:01)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222722723">said</a>:</p>
<blockquote>
<p>I think we'll soon be able to support all kinds of pointer shenanigans. Imo there shouldn't be any <code>Deref</code> impls that aren't <code>const</code>, unless you are explicitly trying to do something nasty</p>
</blockquote>
<p>The problem with that is things like <code>std::lazy::Lazy</code> and <code>std::lazy::SyncLazy</code> (as well as the guard type from <code>lazy-static</code>), which can invoke a user-provided initialization function. In all cases, if these were required to be <code>const</code> functions, they would defeat the purpose (which is, at least for lazy-static, to store objects of a type that cannot be constructed at compile time, such as a Mutex, in a <code>static</code>). If we also include <code>DerefMut</code>, <code>std::borrow::Cow</code> would also fail this test, because it's entire point is that it can invoke a <em>user-provided</em> Clone function whenever mutable access is given. So there are, in fact, legitimate implementations of both that are neither pure nor const (even after raw ptr deref becomes valid in const).</p>



<a name="222728344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728344">(Jan 14 2021 at 15:02)</a>:</h4>
<p>if we make <code>Cow</code> generic over <code>AllocRef</code> we can make it <code>const</code> according to the current heap plan</p>



<a name="222728351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728351">(Jan 14 2021 at 15:02)</a>:</h4>
<p>Those are all idempotent though, and that's what we need for exhaustiveness</p>



<a name="222728426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728426">(Jan 14 2021 at 15:02)</a>:</h4>
<p>even Lazy could work some day, as long as the lazy is in a static and does not use a static by name in a const fn</p>



<a name="222728547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728547">(Jan 14 2021 at 15:03)</a>:</h4>
<p>I could imagine a Lazy that does a database fetch/fs read, which really can never be const right?</p>



<a name="222728695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728695">(Jan 14 2021 at 15:04)</a>:</h4>
<p>Indeed, or that loads entries for a static registery from a file.</p>



<a name="222728703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728703">(Jan 14 2021 at 15:04)</a>:</h4>
<p>So I'm not a fan of using const as a criterion here, if what we really need is idempotence</p>



<a name="222728738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728738">(Jan 14 2021 at 15:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="245339">Nadrieril</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222728547">said</a>:</p>
<blockquote>
<p>I could imagine a Lazy that does a database fetch/fs read, which really can never be const right?</p>
</blockquote>
<p>yea, that's true</p>



<a name="222728766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728766">(Jan 14 2021 at 15:05)</a>:</h4>
<p>though...</p>



<a name="222728788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728788">(Jan 14 2021 at 15:05)</a>:</h4>
<p>if you make the fetching method a generic parameter, then it works again</p>



<a name="222728935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728935">(Jan 14 2021 at 15:06)</a>:</h4>
<p>hm, really? doesn't that mean you could use that to make non-idempotent derefs?</p>



<a name="222728945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222728945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222728945">(Jan 14 2021 at 15:06)</a>:</h4>
<p>anyway, for deref patterns I would have thought we want the deref to be trivial, not just idempotent</p>



<a name="222729041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729041">(Jan 14 2021 at 15:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="245339">Nadrieril</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222728935">said</a>:</p>
<blockquote>
<p>hm, really? doesn't that mean you could use that to make non-idempotent derefs?</p>
</blockquote>
<p>yea, const just means const at compile-time. The current plan is that you can call arbitrary things if they are generic arguments</p>



<a name="222729084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729084">(Jan 14 2021 at 15:07)</a>:</h4>
<p>(but at compile-time, only some generic arguments are allowed)</p>



<a name="222729130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729130">(Jan 14 2021 at 15:07)</a>:</h4>
<p>if I understand correctly then forcing deref to be const doesn't force it to be idempotent? I thought that was the point</p>



<a name="222729269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729269">(Jan 14 2021 at 15:08)</a>:</h4>
<p>as in, if we want pattern exhaustiveness we need at least idempotency, since we decided we couldn't just commit to a single call to deref()</p>



<a name="222729278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729278">(Jan 14 2021 at 15:08)</a>:</h4>
<p>If it was const, or pure by the definition I gave, it would be guaranteed to be idempotent.</p>



<a name="222729350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729350">(Jan 14 2021 at 15:09)</a>:</h4>
<p>But both are, as noted, more restrictive then merely idempotent.</p>



<a name="222729365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729365">(Jan 14 2021 at 15:09)</a>:</h4>
<p>that's what I thought, but <span class="user-mention" data-user-id="124288">@oli</span> said that generic args could allow weird things even in the const case</p>



<a name="222729456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729456">(Jan 14 2021 at 15:09)</a>:</h4>
<p>I could just be confused</p>



<a name="222729468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729468">(Jan 14 2021 at 15:10)</a>:</h4>
<p>My question is what idempotency needs. Would merely structural stability be necessary?</p>



<a name="222729542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729542">(Jan 14 2021 at 15:10)</a>:</h4>
<p>Would it need address stability+structural stability?</p>



<a name="222729641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729641">(Jan 14 2021 at 15:11)</a>:</h4>
<p>hm, for match exhaustiveness to be sound I think only structural stability</p>



<a name="222729739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729739">(Jan 14 2021 at 15:11)</a>:</h4>
<p>but if you don't have address stability then users could observe which derefs have been made which might be surprising</p>



<a name="222729772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222729772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222729772">(Jan 14 2021 at 15:11)</a>:</h4>
<p>I don't think const is the right abstraciton level here, especially around <code>DerefMut</code>, as that could access a <code>&amp;mut</code> stored in the struct and modify it</p>



<a name="222730216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222730216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222730216">(Jan 14 2021 at 15:14)</a>:</h4>
<p>should we have some kind of document to keep track of the things like that we've discussed?</p>



<a name="222730234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222730234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222730234">(Jan 14 2021 at 15:14)</a>:</h4>
<p>For completeness, the structural stability requirement I contemplated states that two consecutive deref/deref_mut operations return references to objects that are structurally equivalent unless an intervening access is made through a mutable reference or a pointer (other then a call to deref_mut)</p>



<a name="222730353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222730353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222730353">(Jan 14 2021 at 15:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="245339">Nadrieril</span> <a href="#narrow/stream/213817-t-lang/topic/Deref.20patterns/near/222730216">said</a>:</p>
<blockquote>
<p>should we have some kind of document to keep track of the things like that we've discussed?</p>
</blockquote>
<p>Possibly. I can throw together a hackmd.</p>



<a name="222730488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222730488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222730488">(Jan 14 2021 at 15:15)</a>:</h4>
<p>hm right, having a <code>ref</code> then a <code>ref mut</code> then a <code>ref</code> patterns on a Cow would break address stability</p>



<a name="222730640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222730640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222730640">(Jan 14 2021 at 15:16)</a>:</h4>
<p>Yeah, and, depending on Clone, it can break structural stability.</p>



<a name="222730688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222730688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222730688">(Jan 14 2021 at 15:16)</a>:</h4>
<p>oh right, that's bad</p>



<a name="222730712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222730712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222730712">(Jan 14 2021 at 15:16)</a>:</h4>
<p>Clone is a safe trait.</p>



<a name="222731078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222731078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222731078">(Jan 14 2021 at 15:18)</a>:</h4>
<p>Cow really cannot be included unless we come up with a way to indicate that Clone is structurally stable (IE. A StructuralClone trait, that perhaps is implemented if Clone is derived and all the fields are StructuralClone)</p>



<a name="222731242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222731242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222731242">(Jan 14 2021 at 15:18)</a>:</h4>
<p>unrelatedly, it seems tricky if we want to allow say matching a <code>Cow&lt;Option&lt;String&gt;&gt;</code> with <code>Some(ref mut s)</code>, because the information for which of <code>deref</code> and <code>deref_mut</code> to use would have to flow backwards</p>



<a name="222731402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222731402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222731402">(Jan 14 2021 at 15:19)</a>:</h4>
<p><code>Cow</code> would be fine as long as we don't mix <code>ref</code> and <code>ref mut</code>, because the impls are idempotent</p>



<a name="222731687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222731687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222731687">(Jan 14 2021 at 15:21)</a>:</h4>
<p>The issue with that is that we'd have to special case cow.</p>



<a name="222731767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222731767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222731767">(Jan 14 2021 at 15:22)</a>:</h4>
<p>Or have some way to disallow mixing deref patterns (or simply disallow the mutable deref patterns for the type)</p>



<a name="222732939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222732939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222732939">(Jan 14 2021 at 15:30)</a>:</h4>
<p>Hackmd for tracking the syntax and requirements questions: <a href="https://hackmd.io/@wSaA8OrrSQ2SlegMvA6e6A/S1VwlyCRD">https://hackmd.io/@wSaA8OrrSQ2SlegMvA6e6A/S1VwlyCRD</a></p>



<a name="222745660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222745660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222745660">(Jan 14 2021 at 16:50)</a>:</h4>
<p>Yeah I was thinking we could disallow mixing deref and deref_mut patterns maybe</p>



<a name="222753200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222753200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222753200">(Jan 14 2021 at 17:38)</a>:</h4>
<p>speaking of structural clones, there's a kind of precedent: consts of custom types in patterns require an automatically-derived <code>PartialEq</code> impl otherwise the user could be surprised that the match is structural instead of using <code>PartialEq</code>. It would not be absurd to require a similarly-autoderived <code>Clone</code> impl for the <code>DerefMut</code> impl of <code>Cow</code></p>



<a name="222754171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222754171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222754171">(Jan 14 2021 at 17:45)</a>:</h4>
<p>hm, an issue of the no-syntax proposal is types that can both be destructured and have a <code>Deref</code> impl:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">cowcow</span>: <span class="nc">Cow</span><span class="o">&lt;</span><span class="n">Cow</span><span class="o">&lt;</span><span class="kt">bool</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
<span class="k">match</span><span class="w"> </span><span class="o">&amp;</span><span class="n">cowcow</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Cow</span>::<span class="n">Owned</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="c1">// what's the type of `x`?</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="222754787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222754787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222754787">(Jan 14 2021 at 17:49)</a>:</h4>
<p>I've expanded the hackmd with most of the points discussed here. I haven't read the irlo thread</p>



<a name="222759107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222759107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222759107">(Jan 14 2021 at 18:17)</a>:</h4>
<p>Also we want to anticipate a future <code>DerefMove</code> possibility. The following should error for now:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="nb">Box</span><span class="o">&lt;</span><span class="nb">Some</span><span class="o">&lt;</span><span class="kt">bool</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
<span class="k">match</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">Some</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="222766392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222766392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222766392">(Jan 14 2021 at 19:06)</a>:</h4>
<p>I've looked into how to file an MCP, and am preparing to do so. <br>
Who all here would like to be initially involved with the project?</p>



<a name="222827787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222827787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222827787">(Jan 15 2021 at 07:42)</a>:</h4>
<p>since when was <code>Cow: DerefMut</code> a thing?! I didn't see <code>DerefMut</code> mentioned at all in <code>Cow</code>'s docs...</p>



<a name="222848558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222848558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222848558">(Jan 15 2021 at 12:01)</a>:</h4>
<p>Huh. I thought it did impl DerefMut, but it has <a href="https://doc.rust-lang.org/std/borrow/enum.Cow.html#method.to_mut">a dedicated method</a>. In this case, it satisfies all the discussed requirements, so it could be a candidate.</p>



<a name="222982954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222982954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222982954">(Jan 16 2021 at 14:07)</a>:</h4>
<p>On the topic of pattern matching, one concern I'd like to add is that before making it more complicated maybe we should first clean up the <a href="https://github.com/rust-lang/rust/issues/74446">currently somewhat messy state of affairs</a> around "structural match"...</p>



<a name="222983493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222983493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222983493">(Jan 16 2021 at 14:16)</a>:</h4>
<p>some of the structural match stuff may already be happening with the edition</p>



<a name="222983519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222983519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222983519">(Jan 16 2021 at 14:17)</a>:</h4>
<p>Don't we first need a plan before anything can happen?^^ Currently all we have is a bunch of ideas.</p>



<a name="222983583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222983583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222983583">(Jan 16 2021 at 14:18)</a>:</h4>
<p>all the ideas revolve around valtrees though so we probably also need those before anything can happen</p>



<a name="222983592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/222983592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#222983592">(Jan 16 2021 at 14:18)</a>:</h4>
<p>edition changes won't help to clean up the codebase so that seems like an orthogonal discussion to me</p>



<a name="228416385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/228416385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#228416385">(Mar 02 2021 at 14:19)</a>:</h4>
<p>I want to chime in and say that I'd very happy to see this come to fruition. Having to write</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">assert_error</span><span class="o">!</span><span class="p">(</span><span class="o">&amp;</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="n">Error</span>::<span class="n">ElementOpenAndCloseMismatched</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">open</span><span class="p">,</span><span class="w"> </span><span class="n">close</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">open</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s">"a"</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="n">close</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s">"b"</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>would be so much nicer as</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">assert_error</span><span class="o">!</span><span class="p">(</span><span class="o">&amp;</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="n">Error</span>::<span class="n">ElementOpenAndCloseMismatched</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">open</span>: <span class="s">"a"</span><span class="p">,</span><span class="w"> </span><span class="n">close</span>: <span class="s">"b"</span><span class="w"> </span><span class="p">});</span><span class="w"></span>
</code></pre></div>



<a name="228416454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/228416454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#228416454">(Mar 02 2021 at 14:19)</a>:</h4>
<p>Plus the ability to finally answer <a href="https://stackoverflow.com/q/25383488/155423">How to match a String against string literals?</a> in a satisfactory manner.</p>



<a name="228419184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/228419184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#228419184">(Mar 02 2021 at 14:34)</a>:</h4>
<p>The Project Group Charter for this is currently on fcp to merge, so assuming no issues are presented, it will be one step closer <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span>.</p>



<a name="228421469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/228421469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#228421469">(Mar 02 2021 at 14:48)</a>:</h4>
<p>Yep! I'm watching that, which is how I got this link. Basically wanted to show encouragement without cluttering up that issue with noise.</p>



<a name="228434041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Deref%20patterns/near/228434041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Deref.20patterns.html#228434041">(Mar 02 2021 at 15:58)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> I should create the zulip stream! sorry about that, will get on that</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>